package com.skyline.base.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.base.model.Footprint;
import com.skyline.base.type.ResourceType;

public class FootprintMapper implements RowMapper<Footprint> {
	public static final String COLUMN_VIEWER_ID = "viewerId";
	public static final String COLUMN_VIEWER_NICKNAME = "viewerNickname";
	public static final String COLUMN_VIEWER_PORTRAIT = "viewerPortrait";
	public static final String COLUMN_VIEWER_EMAIL = "viewerEmail";
	public static final String COLUMN_RESOURCE_ID = "resourceId";
	public static final String COLUMN_RESOURCE_TYPE = "resourceType";
	public static final String COLUMN_LAST_VISIT_TIME = "lastVisitTime";
	
	private static final FootprintMapper MAPPER = new FootprintMapper();
	
	public static FootprintMapper getMapper() {
		return MAPPER;
	}

	@Override
	public Footprint mapRow(ResultSet rs, int rowNum) throws SQLException {
		Footprint fp = new Footprint();
		fp.setViewerId(rs.getLong(COLUMN_VIEWER_ID));
		fp.setViewerNickname(rs.getString(COLUMN_VIEWER_NICKNAME));
		fp.setViewerPortrait(rs.getString(COLUMN_VIEWER_PORTRAIT));
		fp.setViewerEmail(rs.getString(COLUMN_VIEWER_EMAIL));
		fp.setResourceId(rs.getLong(COLUMN_RESOURCE_ID));
		fp.setResourceType(ResourceType.valueOf(rs.getString(COLUMN_RESOURCE_TYPE)));
		fp.setLastVisitTime(rs.getTimestamp(COLUMN_LAST_VISIT_TIME));
		return fp;
	}
}
